package com.yixing.tech.wms.controller;

import com.yixing.tech.common.base.BaseControl;
import com.yixing.tech.common.base.BaseResponse;
import com.yixing.tech.common.base.Rs;
import com.yixing.tech.common.base.BusinessException;
import com.yixing.tech.wms.service.WcsWmsCallbackService;
import com.yixing.tech.wms.stock.out.callback.error.TaskErrorCallbackVO;
import com.yixing.tech.common.entity.WCSTaskCallbackVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 对接wcs 回调
 *
 * @author yixing tech
 * @since 1.0.0
 */
@Slf4j
@CrossOrigin
@RestController
@RequestMapping(value = "/wcs/callback")
public class WcsCallbackController extends BaseControl {

    @Resource
    WcsWmsCallbackService wcsWmsCallbackService;

    @PostMapping("/callback")
    public Rs<Object> callback(@RequestBody WCSTaskCallbackVO callbackVO) throws BusinessException {
        log.info("入库 callback, 请求参数:{}", callbackVO);
        wcsWmsCallbackService.handleCallback(callbackVO.getTaskCode(), callbackVO.getMethod(),
                callbackVO.getCurrentPositionCode(), callbackVO.getPodCode());

        BaseResponse<Object> response = new BaseResponse<>();
        response.setCode(1000);
        response.setDesc("任务节点反馈接收成功!");
        return response;
    }


    @PostMapping("/error/callback")
    public Rs<Object> errorCallback(@RequestBody TaskErrorCallbackVO callbackVO) throws BusinessException {
        log.error("入库 errorCallback, 请求参数:{}", callbackVO);
        Object data = wcsWmsCallbackService.handleErrorCallback(callbackVO);
        BaseResponse<Object> response = new BaseResponse<>();
        response.setCode(1000);
        response.setData(data);
        response.setDesc("任务节点反馈接收成功!");
        return response;
    }

}
